package com.example.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.service.impl.AutoCbsServerImpl;
import com.example.service.impl.AutoJobcArdSTServerImpl;
import com.example.service.impl.Util;

@RestController
@Component
@RequestMapping("AutoJobcardST")
public class AutoJobcardSTController extends Util {

	@Autowired
	public AutoJobcArdSTServerImpl AutoJobcArdServer;
	@Autowired
	public AutoCbsServerImpl AutoCbsServer;

	/**
	 * 自动生成结构专业Jobcard
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("GenerateJobcard")
	@ResponseBody
//	@Scheduled(cron = "0 0 */1 * * ?") // 每小时触发一次
	public String auto_GenerateJobcard_ST() throws IOException {
		Calendar ca = Calendar.getInstance();// 得到一个Calendar的实例
		ca.setTime(new Date()); // 设置时间为当前时间

		Date lastMonth = ca.getTime(); // 结果
		SimpleDateFormat yyyyMMddDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String yyyyMMdd = yyyyMMddDate.format(lastMonth);
		System.err.println("时间：" + yyyyMMdd + "执行了ST专业 自动生成JOBCARD");

		AutoJobcArdServer.auto_GenerateJobcard_ST(); // 自动生成JOBCARD
		return "Success";

	}

	/**
	 * 自动备料与下发结构专业Jobcard
	 * 
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("IssuedJobcardST")
	@ResponseBody
//	@Scheduled(cron = "0 0 8,12,15,18 * * ?") // 每天的 8,12,15,18 点触发一次
	public String auto_IssuedJobcardST() throws IOException {
		Calendar ca = Calendar.getInstance();// 得到一个Calendar的实例
		ca.setTime(new Date()); // 设置时间为当前时间
		Date lastMonth = ca.getTime(); // 结果
		SimpleDateFormat yyyyMMddDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String yyyyMMdd = yyyyMMddDate.format(lastMonth);
		System.err.println("时间：" + yyyyMMdd + "执行了ST专业 自动备料");
		AutoJobcArdServer.auto_IssuedJobcardST();// 自动备料
		return "Success";

	}

}
